﻿<?php
include_once(dirname(__FILE__).'/../lib/Db.class.php');
include_once(dirname(__FILE__).'/Product.class.php');
include_once(dirname(__FILE__).'/ProductFactory.class.php');
class T1Factory implements ProductFactory{
    private $db;

    function __construct(){
        $this->db = Db::getInstance();
    }
    public function createProduct($product_id){
        $sql = "SELECT materialTypeID,text as name,quantity 
            FROM invtypematerials,trntranslations 
            where typeID = ".$product_id." and materialTypeID = keyID 
            and languageID = 'zh' and tcID = (select tcID 
            from trntranslationcolumns where columnName = 'typeName');";

        // 回调函数，获取材料列表
        $getMaterials = function($query_result){
            $materials = array();
            if(is_array($query_result)){
                foreach($query_result as $row){
                    $material = array('id'=>$row->materialTypeID,
                        'name'=>$row->name,
                        'quantity'=>$row->quantity,
                        'damage_per_job'=>1);
                    array_push($materials,$material);
                }
            }
            return $materials;
        };

        $materials = $this->db->db_query($sql,$getMaterials);
        $product = new Product($product_id,$materials);
        return $product;
    }
}
?>
